

*** Figure H.13:  Analysis on early adopters ( observational learning ) 

use "$datadir\ewallet\mid_adopters.dta", clear
		g pre = time >= 201611 & time <= 201701
				
		sort merchant_id time 
		by merchant_id: egen pre_transaction = total(pre*transaction)
		
		drop if time < 201611 
		
		local censusyear 2001
		egen time_id = group(time)
		replace state = "ANDAMAN AND NICOBAR" if state == "ANDAMAN AND NICOBAR ISLANDS"
		merge m:1 state district using "$datadir\\districts\districts_crosswalk.dta"
		drop if _m == 1
		bys state_census`censusyear' district_census`censusyear': egen maxmerge = max(_m)
		drop if maxmerge == 3 & _m != 3
		replace amount  = 0 if maxmerge == 2
		replace transaction  = 0 if maxmerge == 2
		drop _m maxmerge
		replace state = state_census`censusyear'
		replace district = district_census`censusyear'
		drop state_census2011 district_census2011 state_census2001 district_census2001
		replace district = trim(district)
		replace state = trim(state)
		duplicates drop
		drop if time == .
		
		preserve
			use "$datadir\ewallet\maindata.dta", clear
			keep if $filters
			bys time: egen exposure_5 = xtile(invshare_sd), nq(3)
			keep time exposure_5 invshare_sd own_sci wtg_sci_exposure district state district_id  state_id large_metro_area threshold_merchants_1000 NE_states_1 share_rural logpop_T l_preshockdeposit201604 s_status_atm s_status_commercialbank
			save "$datadir\temp.dta", replace
		restore
		
		merge m:1 district state time using "$datadir\temp.dta" 
		keep if _m == 3
		drop _m
		erase "$datadir\temp.dta" 
		
		
		g logtrans = log(1+transaction)
		g log_pretrans = log(1+pre_transaction)
		
		keep if time == 201703 | time == 201706
		sort merchant_id time 
		by merchant_id: g d_trans_2 = (transaction - transaction[_n-1])/transaction[_n-1]
		
	
		binscatter d_trans_2 invshare_sd, nq(50) control(share_rural logpop_T l_preshockdeposit201604 s_status_atm s_status_commercialbank) mcolor(gs7) lcolor(black)  xtitle("Exposure{subscript:d}") ylab(,nogrid) ytitle("% change in # of transactions (Mar-Jun 2017)")
		graph export "$outputdir_fig\Figure_H13_1.pdf",  as(pdf) replace
		binscatter d_trans_2 invshare_sd, nq(50) control(share_rural logpop_T l_preshockdeposit201604 s_status_atm s_status_commercialbank log_pretrans) mcolor(gs7) lcolor(black)  xtitle("Exposure{subscript:d}") ylab(,nogrid) ytitle("% change in # of transactions (Mar-Jun 2017)")
		graph export "$outputdir_fig\Figure_H13_2.pdf",  as(pdf) replace
		
	
		
